<?php
namespace Admin\Controller;
use Think\Controller;
class RateController extends IndexController {
    
    public function lists(){
        $rate=D("Rate");
        $rr=$rate->select();
        foreach($rr as &$v){
            $v['name']="从".$v['from_bz']."转".$v['to_bz']."的汇率为:";
        }
        $this->assign('rate',$rr);
        $this->display();
    }
    public function update($val,$from_bz,$to_bz){
        $rate=D("Rate");
        $RateLog=D("RateLog");
        $data['rate_val']=$val;
        $data['update_time']=time();
        $rr=$rate->where("from_bz='".$from_bz."' and to_bz='".$to_bz."'")->save($data);
        if(!$rr){
            echo json_encode(0);exit;
        }
        $opt['log']="汇率管理员".$_SESSION['name']."修改了从".$from_bz."到".$to_bz."的汇率为".$val;
        $opt['create_time']=time();
        $RateLog->add($opt);
        echo json_encode(1);exit;
    }
}